#ifndef TASKEDITDIALOG_H
#define TASKEDITDIALOG_H

#include <QDialog>
#include <QSqlDatabase>
#include <QDateTime>
#include "calendaritem.h"

namespace Ui {
    class TaskEditDialog;
}

class TaskEditDialog : public QDialog
{
    Q_OBJECT

public:
    explicit TaskEditDialog(QWidget *parent = 0, QSqlDatabase db=QSqlDatabase(), int userid=0, const QDateTime& start=QDateTime(), const QDateTime& end=QDateTime());
    explicit TaskEditDialog(QWidget *parent, QSqlDatabase db, int userid, const CalendarItem& item);
    ~TaskEditDialog();

    void accept();

private slots:
    void on_companyComboBox_currentIndexChanged(int index);
    void on_productComboBox_currentIndexChanged(int index);
    void on_componentComboBox_currentIndexChanged(int index);
    void on_categoryComboBox_currentIndexChanged(int index);
    void on_startEdit_dateTimeChanged(const QDateTime &date);
    void on_endEdit_dateTimeChanged(const QDateTime &date);
    void on_removeTaskButton_clicked();

private:
    void initialize(const QDateTime& start, const QDateTime& end, const QString& comment=QString());
    void initializeCompanyCombo();
    void initializeProductCombo(int companyID);
    void initializeComponentCombo(int productID);
    void initializeCategoryCombo(int productID);
    bool noError() const;

    Ui::TaskEditDialog *ui;
    QSqlDatabase db_;
    int companyID_;
    int userID_;
    int taskID_;
    int prodID_;
    int compID_;
    int cateID_;
};

#endif // TASKEDITDIALOG_H
